<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Checks if a SOAP call has failed</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.is-soap-fault" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">is_soap_fault</h1>
  <p class="verinfo">(PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">is_soap_fault</span> &mdash; <span class="dc-title">Checks if a SOAP call has failed</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.is-soap-fault-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>is_soap_fault</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$object</code></span>
   ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   This function is useful to check if the SOAP call failed, but
   without using exceptions. To use it, create a 
   <a href="class.soapclient.html" class="classname">SoapClient</a> object with the <em>exceptions</em>
   option set to zero or <strong><code>FALSE</code></strong>.
   In this case, the SOAP method will return a special 
   <a href="class.soapfault.html" class="classname">SoapFault</a> object which encapsulates the fault 
   details (faultcode, faultstring, faultactor and faultdetails).
  </p>
  <p class="para">
   If <em>exceptions</em> is not set then SOAP call will throw
   an exception on error.
   <span class="function"><strong>is_soap_fault()</strong></span> checks if the given
   parameter is a <a href="class.soapfault.html" class="classname">SoapFault</a> object.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.is-soap-fault-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">object</code></dt>

     <dd>

      <p class="para">
       The object to test.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.is-soap-fault-returnvalues">
  <h3 class="title">返回值</h3>
  
  <p class="para">
   This will return <strong><code>TRUE</code></strong> on error, and <strong><code>FALSE</code></strong> otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.is-soap-fault-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-6404">
    <p><strong>Example #1 <span class="function"><strong>is_soap_fault()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"some.wsdl"</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #DD0000">'exceptions'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">SomeFunction</span><span style="color: #007700">();<br />if&nbsp;(</span><span style="color: #0000BB">is_soap_fault</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"SOAP&nbsp;Fault:&nbsp;(faultcode:&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">faultcode</span><span style="color: #007700">}</span><span style="color: #DD0000">,&nbsp;faultstring:&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">faultstring</span><span style="color: #007700">}</span><span style="color: #DD0000">)"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
   <div class="example" id="example-6405">
    <p><strong>Example #2 SOAP&#039;s standard method for error reporting is exceptions</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">try&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$client&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SoapClient</span><span style="color: #007700">(</span><span style="color: #DD0000">"some.wsdl"</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$client</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">SomeFunction</span><span style="color: #007700">(</span><span style="color: #FF8000">/*&nbsp;...&nbsp;*/</span><span style="color: #007700">);<br />}&nbsp;catch&nbsp;(</span><span style="color: #0000BB">SoapFault&nbsp;$fault</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">trigger_error</span><span style="color: #007700">(</span><span style="color: #DD0000">"SOAP&nbsp;Fault:&nbsp;(faultcode:&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$fault</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">faultcode</span><span style="color: #007700">}</span><span style="color: #DD0000">,&nbsp;faultstring:&nbsp;</span><span style="color: #007700">{</span><span style="color: #0000BB">$fault</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">faultstring</span><span style="color: #007700">}</span><span style="color: #DD0000">)"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">E_USER_ERROR</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.is-soap-fault-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="soapclient.soapclient.html" class="methodname" rel="rdfs-seeAlso">SoapClient::SoapClient()</a> - SoapClient constructor</span></li>
    <li class="member"><span class="methodname"><a href="soapfault.soapfault.html" class="methodname" rel="rdfs-seeAlso">SoapFault::SoapFault()</a> - SoapFault constructor</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>